package cn.yeziji.forum.dto.answer;

import cn.yeziji.forum.entity.ForumAnswerEntity;
import lombok.Data;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * 答案数据对象
 *
 * @author gzkemays
 * @since 2022/11/14 7:43 PM
 */
@Data
public class AnswerDTO {
  @NotNull(message = "没有指定对象")
  Integer id;

  @NotNull(message = "定义模式失败")
  @Max(value = 1)
  @Min(value = 0)
  Integer mode;

  @NotBlank(message = "没有回复任何内容")
  String content;

  public ForumAnswerEntity answerEntity() {
    ForumAnswerEntity entity = new ForumAnswerEntity();
    entity.setContent(content);
    return entity;
  }

  public ForumAnswerEntity replayEntity() {
    ForumAnswerEntity entity = new ForumAnswerEntity();
    entity.setContent(content);
    entity.setParentAnswerId(id);
    return entity;
  }
}
